<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >  
    <ui:composition template="layout.xhtml">

        <ui:define name="corpo">
            <h:form id="incluir_form_entrada" acceptcharset="utf-8" prependId="false"> 
                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('config.xhtml')}" value="Configurações" update="@form" immediate="true"/> >
                    <p:commandLink  value="Solicitar Selo" update="@form" immediate="true"/>
                </div>
                <p:panel header="Fermojupi - Solicitação dos Selos de Fiscalização">
                    <p:messages id="msg"/>
                    <fieldset>
                        <legend>Cabeçalho da Entrada</legend>
                        <h:panelGrid columns="2"  id="panelEntrada"   border="0" styleClass="textAlignRight" columnClasses="textAlignRight"> 
                            <p:row>
                                <h:outputLabel value=" * " style="color:red;float:right"/>
                                <h:outputLabel value="Tipo Selo: "/>

                            </p:row>
                            <p:autoComplete id="tipoSelo" panelStyle="width:250px !important;" effect="blind" value="#{managerPedido.pedidoSelo.tipoSelo}" size="20" completeMethod="#{managerTipoSelo.completeTipoSelo}"  
                                            var="p" itemLabel="#{p.nome}"   itemValue="#{p}" converter="tipoSeloConverter" forceSelection="true" 
                                            converterMessage="Erro, verifique o Tipo Selo" minQueryLength="3" dropdown="true" required="true" requiredMessage="O campo 'Tipo Selo' é obrigatório"> 
                                <p:ajax event="itemSelect" listener="#{managerEntrada.handleSelectTipoSelo}"/>   
                                <p:column   >  
                                    <table >
                                        <tr  style="height:20px; background-color: \##{p.corSelo.cor};">
                                            <td style="width: 20px;"></td>
                                        </tr>
                                    </table>
                                </p:column>
                                <p:column>  
                                    #{p.nome}
                                </p:column>  
                            </p:autoComplete>
                            <p:row>
                                <h:outputLabel value=" * " style="color:red;float:right"/>
                                <h:outputLabel value="Quantidade de Folhas: "/>
                            </p:row>
                            <p:inputText value="#{managerPedido.pedidoSelo.qtdFolhas}" />
                            <p:row>
                                <h:outputLabel value=" * " style="color:red;float:right"/>
                                <h:outputLabel value="Selos por Folha: "/>
                            </p:row>
                            <p:inputText value="#{managerPedido.pedidoSelo.qtdSelosFolha}" />  
                            
                            </h:panelGrid>
                            <p:row>
                                <center>
                                    
                                    <p:commandButton value="Adicionar" icon="ui-icon-circle-plus" update="@form"
                                                     actionListener="#{managerPedido.addList()}" />                                    
                                </center>
                            </p:row>
                            <br/>
                            <p:dataTable id="tabledetalhe" var="pedi" 
                                         value="#{managerPedido.pedidoSelos}"
                                         rowIndexVar="rowid" emptyMessage="Nenhuma entrada de selo">
                                <f:facet name="header">
                                    <h:outputText value="Pedido"/>
                                </f:facet>
                                <p:column headerText="Tipo Selo" style="width: 50px; text-align: center;">
                                    <h:outputText value="#{pedi.tipoSelo.nome}"/>
                                </p:column>
                                 <p:column headerText="Cor" style="width: 50px">
                                    <h:outputText value=""/>
                                    <table>
                                        <tr class="borderZero" style="height:30px; background-color: \##{pedi.tipoSelo.corSelo.cor};">
                                            <td class="borderZero" style="width: 20px;"></td>
                                        </tr>
                                    </table>
                                </p:column>
                                <p:column headerText="Quantidade de Folhas" style="width: 50px; " >
                                    <h:outputText value="#{pedi.qtdFolhas}" style="float: right"/>
                                </p:column>
                                <p:column headerText="Selos por Folha " style="width: 50px">
                                    <h:outputLabel  value="#{pedi.qtdSelosFolha}"  style="float: right" />
                                </p:column>
                                <p:column headerText="Quantidade de Selos" style="width: 50px">
                                    <h:outputText value="#{pedi.qtdSelos}" style="float: right"/>
                                </p:column>
                                <p:column headerText="Valor Unit." style="width: 40px">
                                    <h:outputText value="#{pedi.emolumento.valorSelo}" style="float: right">
                                            <f:convertNumber pattern="#,##0.00" minFractionDigits="2"  />  
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="Valor do Pedido" style="width: 50px">
                                    <h:outputText value="#{managerPedido.valorPedido(pedi.qtdSelos, pedi.emolumento.valorSelo)}" style="float: right">
                                            <f:convertNumber pattern="#,##0.00" minFractionDigits="2"  />  
                                    </h:outputText>
                                </p:column>
                                <p:column style="width: 20px;" headerText="Opções">
                                    <p:commandButton  style="width: 20px; height: 20px; float: right;" onclick="removeRC({paramPedido:#{rowid}})" icon="editar"/>
                                    <p:commandButton style="width: 20px; height: 20px; float: right;" icon="ui-icon-trash"  actionListener="#{managerPedido.removeList(pedi)}" process="@this" update="@form" immediate="true"/>
                                </p:column>
                                <f:facet name="footer">
                                     <h:outputText value="Total   R$ #{managerPedido.somaPedido()}" style="float: right; margin-right: 80px"/>
                                    
                                </f:facet>
                            </p:dataTable>                           

                            <p:remoteCommand name="removeRC"
                                             update="tabledetalhe, panelEntrada" process="@this" actionListener="#{managerPedido.editList()}">
                            </p:remoteCommand>
                        
                    </fieldset>
                    <center>
                        <p:commandButton icon="ui-icon-arrowreturnthick-1-w" value="Cancelar" actionListener="#{managerIndex.redirect('config.xhtml')}" update="@form" immediate="true"/>
                     <p:commandButton value="Solicitar Selos" icon="ui-icon-circle-plus" update="@form"
                        actionListener="#{managerPedido.addList()}" />                                    
                    </center>
                </p:panel>               
            </h:form>
        </ui:define>
    </ui:composition>
</html>
